<?php
//data_sekolah_page.php

/**
 * Fungsi ini berguna untuk menampilkan form sekolah pada admin WordPress
 */

function input_data(){
	$crud = $_REQUEST['crud'];

	switch ($crud){
		case "read": read_data_sekolah();break;
		case "create": create_data_sekolah();break;
		case "update": update_data_sekolah();break;
		case "delete": delete_data_sekolah();break;
		default: panel_data_sekolah();break;
		case "guru": lihat_data_guru();break;
		case "form": form_update_data_sekolah();break;
		case "telah":telah_update_data_sekolah();break;
	}
	//echo "<pre>"; print_r($GLOBALS); echo "</pre>";

}

function panel_data_sekolah(){
	?><h2>Menu :</h2>
	<h3><a href="admin.php?page=<?=$_REQUEST['page']?>&crud=read">Lihat</a> Data Alumni</h3>
	<h3><a href="admin.php?page=<?=$_REQUEST['page']?>&crud=create">Tambah</a> Data Alumni</h3>
	<h3><a href="admin.php?page=<?=$_REQUEST['page']?>&crud=update">Ubah</a> Data Alumni</h3>
	<h3><a href="admin.php?page=<?=$_REQUEST['page']?>&crud=delete">Hapus</a> Data Alumni</h3>
	
	<?
}


function lihat_data_guru(){

	global $wpdb;
	$nama_sekolah = $wpdb->get_results("SELECT nama FROM alumni_polkam WHERE nim='".$_REQUEST['nim']."';");
		
	?><h2>Alumni Politeknik Kampar <?=$nama[0]->nama;?> :</h2><?php

		$fivesdrafts = $wpdb->get_results
		("	SELECT * FROM alumni_polkam WHERE alumni_polkam.nim='".$_REQUEST['nim']. "';");
	echo "<table>
	<th width=1><center>No</th></center>
	<th width=1><center>Foto</th></center>
	<th width=5><center>NIM</th></center>
	<th width=200><center>Nama Alumni</th></center>
	<th width=150><center>Tempat Lahir</th></center>
	<th width=150><center>Tanggal Lahir</th></center>
	<th width=500><center>Alamat</th></center>
	<th width=25><center>No Hp</th></center>
	<th width=15><center>Email</th></center>
	<th width=15><center>Blog</th></center>
	<th width=400><center>Program Studi Angkatan</th></center>
	<th width=15><center>Angkatan</th></center>
	</tr>";
	
	$L=1;
	foreach ( $fivesdrafts as $alumni_polkam) 
	{
		echo "<tr class='hentry alternate'><td align=center>".$L++ . " </td>
		<td align=center>" .$alumni_polkam->foto .  " </td>
		<td align=center>" .$alumni_polkam->nim .  " </td>
		<td align=center>" .$alumni_polkam->nama .  " </td>
		<td align=center>" .$alumni_polkam->tempat_lahir .  " </td>
		<td align=center>" .$alumni_polkam->tanggal_lahir.  " </td>
		<td align=center>" .$alumni_polkam->alamat.  " </td>
		<td align=center>" .$alumni_polkam->no_hp.  " </td>
		<td align=center>" .$alumni_polkam->email.  " </td>
		<td align=center>" .$alumni_polkam->blog.  " </td>
		<td align=center>" .$alumni_polkam->program_studi.  " </td>
		<td align=center>" .$alumni_polkam->angkatan.  " </td>
		</tr>";
	}
	echo "</table>";
	?>
		<h3><a href="admin.php?page=<?=$_REQUEST['page']?>&crud=read&nss=<?=$_REQUEST['nss']?>">Kembali</a></h3>
	<?
}


function delete_data_sekolah(){
	global $wpdb;
	//kalau sudah ada $nss yang ingin di delete, maka hapus
	if(trim($_REQUEST['nss']!='')){
		//hapus dari database
		$nss = $_REQUEST['nss'];
		$wpdb->query("DELETE from sekolah where nss='$nss';");
	}
	//tampilkan semua sekolah:
		$fivesdrafts = $wpdb->get_results("SELECT * FROM sekolah;");
	echo "<table>
	<tr>
	<th width=1><center>No</th></center>
	<th width=5><center>NSS</th></center>
	<th width=20><center>Nama Sekolah</th></center>
	<th width=35><center>Alamat</th></center>
	<th width=15><center>Status</th></center>
	<th width=12><center>Desa</th></center>
	<th width=25><center>Kecamatan</th></center>
	<th width=15><center>Kode Pos</th></center>
	<th width=15><center>Kota</th></center>
	<th width=15><center>Provinsi</th></center>
	<th width=12><center>Telepon</th></center>
	<th width=20><center>No fax</th></center>
	<th width=20><center>Email</th></center>
	<th width=20><center>Website</th></center>
	<th width=20><center>Siswa Kelas X</th></center>
	<th width=20><center>Siswa Kelas XI</th></center>
	<th width=20><center>Siswa Kelas XII</th></center>
	<th width=15><center>Rombel Kelas XI IPA</th></center>
	<th width=15><center>Rombel Kelas XI PS</th></center>
	<th width=15><center>Rombel Kelas XI BHS</th></center>
	<th width=15><center>Rombel Kelas XII IPA</th></center>
	<th width=15><center>Rombel Kelas XII IPS</th></center>
	<th width=15><center>Rombel Kelas XII BHS</th></center>
	<th width=15><center>Hapus</th></center>
	</tr>";

	$L=1;
	foreach ( $fivesdrafts as $sekolah ) 
	{
		echo "<tr class='hentry alternate'><td align=center>".$L++ . " </td>
		<td align=center>" .$sekolah->nss .  " </td>
		<td align=center>". $sekolah->nama_sekolah.  " </td>
		<td align=center>" .$sekolah->alamat .  " </td>
		<td align=center>" .$sekolah->status.  " </td>
		<td align=center>" .$sekolah->desa.  " </td>
		<td align=center>" .$sekolah->kecamatan.  " </td>
		<td align=center>" .$sekolah->kode_pos.  " </td>
		<td align=center>" .$sekolah->kota.  " </td>
		<td align=center>" .$sekolah->provinsi.  " </td>
		<td align=center>" .$sekolah->telp.  " </td>
		<td align=center>" .$sekolah->fax.  " </td>
		<td align=center>" .$sekolah->email ."</td>
		<td align=center>" .$sekolah->website.  " </td>
		<td align=center>" .$sekolah->siswa_x ."</td>
		<td align=center>" .$sekolah->siswa_xi ."</td>
		<td align=center>" .$sekolah->siswa_xii ."</td>
		<td align=center>" .$sekolah->rombel_x ."</td>
		<td align=center>" .$sekolah->rombel_xiipa ."</td>
		<td align=center>" .$sekolah->rombel_xiips ."</td>
		<td align=center>" .$sekolah->rombel_xibhs ."</td>
		<td align=center>" .$sekolah->rombel_xiiipa ."</td>
		<td align=center>" .$sekolah->rombel_xiiips ."</td>
		<td align=center>" .$sekolah->rombel_xiibhs ."</td>
		<td>"."<a href=\"".admin_url('admin.php')."?page=".$_REQUEST['page']."&crud=delete&nss=". $sekolah->nss ."\">Hapus</a></td></tr>";
		
	}
	
	echo "</table>";
	?>
		<h3><a href="admin.php?page=<?=$_REQUEST['page']?>&crud=panel">Kembali</a></h3>
	<?
}

function create_data_sekolah(){
	global $wpdb;
    ?><div class="wrap">
    <div id="icon-users" class="icon32"></div>
    <h2>Penginputan Data Penelitian</h2>
    Lengkapi data penelitian di bawah ini :';
	<?
	
    //check if option is set before saving
    if ( isset( $_POST['nama_sekolah'] ) ) {
        //retrieve the option value from the form
        $nss =  $_POST['nss'] ;
		$nama_sekolah =  $_POST['nama_sekolah'] ;
		$alamat =  $_POST['alamat'] ;
		$status =  $_POST['status'] ;
		$desa =  $_POST['desa'] ;
		$kecamatan =  $_POST['kecamatan'] ;
		$kode_pos =  $_POST['kode_pos'] ;
		$kota =  $_POST['kota'] ;
		$provinsi =  $_POST['provinsi'] ;
		$telp =  $_POST['telp'] ;
		$fax =  $_POST['fax'] ;
		$email =  $_POST['email'] ;
		$website =  $_POST['website'] ;
		$kelas_x =  $_POST['kelas_x'] ;
		$kelas_xi =  $_POST['kelas_xi'] ;
		$kelas_xii =  $_POST['kelas_xii'] ;
		$rombel_x =  $_POST['rombel_x'] ;
		$rombel_xiipa =  $_POST['rombel_xiipa'] ;
		$rombel_xiips =  $_POST['rombel_xiips'] ;
		$rombel_xibhs =  $_POST['rombel_xibhs'] ;
		$rombel_xiiipa =  $_POST['rombel_xiiipa'] ;
		$rombel_xiiips =  $_POST['rombel_xiiips'] ;
		$rombel_xiibhs =  $_POST['rombel_xiibhs'] ;
		$wpdb->query("INSERT INTO `sekolah` (
		`nss` ,
		`nama_sekolah` ,
		`alamat` ,
		`status` ,
		`desa` ,
		`kecamatan` ,
		`kode_pos` ,
		`kota` ,
		`provinsi` ,
		`telp` ,
		`fax` ,
		`email` ,
		`website` ,
		`kelas_x` ,
		`kelas_xi` ,
		`kelas_xii` ,
		`rombel_x` ,
		`rombel_xiipa` ,
		`rombel_xiips` ,
		`rombel_xibhs` ,
		`rombel_xiiipa` ,
		`rombel_xiiips` ,
		`rombel_xiibhs`
		)
		VALUES ('$nss', '$nama_sekolah', '$alamat', '$status', '$desa', '$kecamatan', '$kode_pos', '$kota', '$provinsi', '$telp', '$fax', '$email', '$website', '$kelas_x', '$kelas_xi', '$kelas_xii', '$rombel_x', '$rombel_xiipa', '$rombel_xiips', '$rombel_xibhs', '$rombel_xiiipa', '$rombel_xiiips', '$rombel_xiibhs');");
	
		echo "<h2>Sukses menyimpan data sekolah ke database</h2>";
		
    }
	?>
	<form id="form1" name="form1" method="post" action="">
		<table width='100%' border='0' cellspacing='2' cellpadding='2' class='form-table' >
			<!--tr>
			  <th><label for="nss">ID Sekolah</label></th>
			  <td>
				<input type="text" id="nss" name="nss" value="<?php echo $nss;?>" class="regular-text">
			  </td>
			</tr-->
		
		<tr>
		  <th><label for="nss">Nomor Statistik Sekolah</label></th>
		  <td>
			<input type="text" id="nss" name="nss" value="<?php echo $nss;?>" class="regular-text">
			<br />
		  </td>
		</tr>

		<tr>
		  <th><label for="nama_sekolah">Nama Sekolah</label></th>
		  <td>
			<input type="text" id="nama_sekolah" name="nama_sekolah" value="<?php echo $nama_sekolah;?>" class="regular-text">
			<br />
		  </td>
		</tr>
		
		<tr>
		  <th><label for="alamat">Alamat</label></th>
		  <td>
			<textarea name="alamat" id="alamat" rows="5" cols="30"><?php echo $alamat;?></textarea>
			<br />
		  </td>
		</tr>
		
		<tr>
		  <th><label for="status">Status</label></th>
		  <td>
			<!-- <input type="text" id="status" name="status" value="<?php echo $status;?>" class="regular-text"> -->
			<SELECT NAME="status" ID="status">
			  <OPTION VALUE=""></OPTION>
			  <OPTION VALUE="NEGERI" <?php selected( $status, 'NEGERI' ); ?>>NEGERI</OPTION>
			  <OPTION VALUE="SWASTA" <?php selected( $status, 'SWASTA' ); ?>>SWASTA</OPTION>
			  <OPTION VALUE="Lainnya" <?php selected( $status, 'Lainnya' ); ?>>Lainnya</OPTION>
			</SELECT>
			<br />
			<span class="description">Pilih status sekolah !. </span>
		  </td>
		</tr>

		<tr>
		  <th><label for="desa">Desa</label></th>
		  <td>
			<input type="text" id="desa" name="desa" value="<?php echo $desa;?>" class="regular-text">
			<br />
		  </td>
		</tr>
		<tr>
		  <th><label for="kecamatan">Kecamatan</label></th>
		  <td>
			<!-- <input type="text" id="kecamatan" name="kecamatan" value="<?php echo $kecamatan;?>" class="regular-text"> -->
			<SELECT NAME="kecamatan" ID="kecamatan">
			  <OPTION VALUE=""></OPTION>
			  <OPTION VALUE="BANGKINANG" <?php selected( $kecamatan, 'BANGKINANG' ); ?>>BANGKINANG</OPTION>
			  <OPTION VALUE="BANGKINANG BARAT" <?php selected( $kecamatan, 'BANGKINANG BARAT' ); ?>>BANGKINANG BARAT</OPTION>
			  <OPTION VALUE="BANGKINANG SEBERANG" <?php selected( $kecamatan, 'BANGKINANG SEBERANG' ); ?>>BANGKINANG SEBERANG</OPTION>
			  <OPTION VALUE="KAMPAR" <?php selected( $kecamatan, 'KAMPAR' ); ?>>KAMPAR</OPTION>
			  <OPTION VALUE="KAMPAR TIMUR" <?php selected( $kecamatan, 'KAMPAR TIMUR' ); ?>>KAMPAR TIMUR</OPTION>
			  <OPTION VALUE="KAMPAR UTARA" <?php selected( $kecamatan, 'KAMPAR UTARA' ); ?>>KAMPAR UTARA</OPTION>
			  <OPTION VALUE="RUMBIO JAYA" <?php selected( $kecamatan, 'RUMBIO JAYA' ); ?>>RUMBIO JAYA</OPTION>
			  <OPTION VALUE="SALO" <?php selected( $kecamatan, 'SALO' ); ?>>SALO</OPTION>
			  <OPTION VALUE="Lainnya" <?php selected( $kecamatan, 'Lainnya' ); ?>>Lainnya</OPTION>
			</SELECT>
			<br />
		  </td>
		</tr>
		
		<tr>
		  <th><label for="kode_pos">Kode Pos</label></th>
		  <td>
			<input type="text" id="kode_pos" name="kode_pos" value="<?php echo $kode_pos;?>" class="regular-text">
			<br />
		  </td>
		</tr>

		<tr>
		  <th><label for="kota">Kab/Kota</label></th>
		  <td>
			<!-- <input type="text" id="kota" name="kota" value="<?php echo $kota;?>" class="regular-text"> -->
			<SELECT NAME="kota" ID="kota">
			  <OPTION VALUE=""></OPTION>
			  <OPTION VALUE="BANGKINANG" <?php selected( $kota, 'BANGKINANG' ); ?>>BANGKINANG</OPTION>
			  <OPTION VALUE="KAMPAR" <?php selected( $kota, 'KAMPAR' ); ?>>KAMPAR</OPTION>
			  <OPTION VALUE="Lainnya" <?php selected( $kota, 'Lainnya' ); ?>>Lainnya</OPTION>
			</SELECT>
			<br />
		  </td>
		</tr>
		
		<tr>
		  <th><label for="provinsi">Provinsi</label></th>
		  <td>
			<!-- <input type="text" id="provinsi" name="provinsi" value="<?php echo $provinsi;?>" class="regular-text"> -->
			<SELECT NAME="provinsi" ID="provinsi">
			  <OPTION VALUE=""></OPTION>
			  <OPTION VALUE="RIAU" <?php selected( $provinsi, 'RIAU' ); ?>>RIAU</OPTION>
			  <OPTION VALUE="Lainnya" <?php selected( $provinsi, 'Lainnya' ); ?>>Lainnya</OPTION>
			</SELECT>
			<br />
		  </td>
		</tr>
		<tr>
		  <th><label for="telp">Telepon</label></th>
		  <td>
			<input type="text" id="telp" name="telp" value="<?php echo $telp;?>" class="regular-text">
			<br />
		  </td>
		</tr>
		<tr>
		  <th><label for="fax">No Fax</label></th>
		  <td>
			<input type="text" id="fax" name="fax" value="<?php echo $fax;?>" class="regular-text">
			<br />
		  </td>
		</tr>
		<tr>
		  <th><label for="email">Email</label></th>
		  <td>
			<input type="text" id="email" name="email" value="<?php echo $email;?>" class="regular-text">
			<br />
		  </td>
		</tr>
		<tr>
		  <th><label for="website">Website</label></th>
		  <td>
			<input type="text" id="website" name="website" value="<?php echo $website;?>" class="regular-text">
			<br />
		  </td>
		</tr>
		<tr>
		  <th><label for="kelas_x">Siswa Kelas X</label></th>
		  <td>
			<input type="text" id="kelas_x" name="kelas_x" value="<?php echo $kelas_x;?>" class="regular-text">
			<br />
		  </td>
		  </tr>
		  <tr>
		  <th><label for="kelas_xi">Siswa Kelas XI</label></th>
		  <td>
			<input type="text" id="kelas_xi" name="kelas_xi" value="<?php echo $kelas_xi;?>" class="regular-text">
			<br />
		  </td>
		  </tr>
		  <tr>
		  <th><label for="kelas_xii">Siswa Kelas XII</label></th>
		  <td>
			<input type="text" id="kelas_xii" name="kelas_xii" value="<?php echo $kelas_xii;?>" class="regular-text">
			<br />
		  </td>
		  </tr>
		  <tr>
		  <th><label for="rombel_x">Rombel Kelas X</label></th>
		  <td>
			<input type="text" id="rombel_x" name="rombel_x" value="<?php echo $rombel_x;?>" class="regular-text">
			<br />
		  </td>
		  </tr>
		  <tr>
		  <th><label for="rombel_xiipa">Rombel Kelas XI IPA</label></th>
		  <td>
			<input type="text" id="rombel_xiipa" name="rombel_xiipa" value="<?php echo $rombel_xiipa;?>" class="regular-text">
			<br />
		  </td>
		  </tr>
		  <tr>
		  <th><label for="rombel_xiips">Rombel Kelas XI IPS</label></th>
		  <td>
			<input type="text" id="rombel_xiips" name="rombel_xiips" value="<?php echo $rombel_xiips;?>" class="regular-text">
			<br />
		  </td>
		  </tr>
		  <tr>
		  <th><label for="rombel_xibhs">Rombel Kelas XI BHS</label></th>
		  <td>
			<input type="text" id="rombel_xibhs" name="rombel_xibhs" value="<?php echo $rombel_xibhs;?>" class="regular-text">
			<br />
		  </td>
		  </tr>
		  <tr>
		  <th><label for="rombel_xiiipa">Rombel Kelas XII IPA</label></th>
		  <td>
			<input type="text" id="rombel_xiiipa" name="rombel_xiiipa" value="<?php echo $rombel_xiiipa;?>" class="regular-text">
			<br />
		  </td>
		  </tr>
		  <tr>
		  <th><label for="rombel_xiiips">Rombel Kelas XII IPS</label></th>
		  <td>
			<input type="text" id="rombel_xiiips" name="rombel_xiiips" value="<?php echo $rombel_xiiips;?>" class="regular-text">
			<br />
		  </td>
		  </tr><tr>
		  <th><label for="rombel_xiibhs">Rombel Kelas XII BHS</label></th>
		  <td>
			<input type="text" id="rombel_xiibhs" name="rombel_xiibhs" value="<?php echo $rombel_xiibhs;?>" class="regular-text">
			<br />
		  </td>
		  </tr>
		  </table><br>
	<b><h3><input type=submit name=submit value=Daftar></h3></b>
	<b><h3><input type=reset name=reset value=Batal></h3></b>
</form>
<h3><a href="admin.php?page=<?=$_REQUEST['page']?>&crud=panel">Kembali</a></h3>
<?
}

function read_data_sekolah(){
	echo "Daftar sekolah yang ada di Kabupaten Kampar adalah sebagai berikut :";
	echo ("<br>");
	echo ("<br>");
	global $wpdb;
		$fivesdrafts = $wpdb->get_results( 
		"SELECT * FROM alumni_polkam ORDER BY nim;");
	echo "<table>
	<tr>
	<th width=1><center>No</th></center>
	<th width=1><center>Foto</th></center>
	<th width=5><center>NIM</th></center>
	<th width=200><center>Nama Alumni</th></center>
	<th width=150><center>Tempat Lahir</th></center>
	<th width=150><center>Tanggal Lahir</th></center>
	<th width=500><center>Alamat</th></center>
	<th width=25><center>No Hp</th></center>
	<th width=15><center>Email</th></center>
	<th width=15><center>Blog</th></center>
	<th width=400><center>Program Studi Angkatan</th></center>
	<th width=15><center>Angkatan</th></center>
	
    <!-- <th width=12><center>Telepon</th></center>
	<th width=20><center>No fax</th></center>
	<th width=20><center>Email</th></center>
	<th width=20><center>Website</th></center>
	<th width=20><center>Siswa Kelas X</th></center>
	<th width=20><center>Siswa Kelas XI</th></center>
	<th width=20><center>Siswa Kelas XII</th></center>
	<th width=15><center>Rombel Kelas X</th></center>
	<th width=15><center>Rombel Kelas XI IPA</th></center>
	<th width=15><center>Rombel Kelas XI PS</th></center>
	<th width=15><center>Rombel Kelas XI BHS</th></center>
	<th width=15><center>Rombel Kelas XII IPA</th></center>
	<th width=15><center>Rombel Kelas XII IPS</th></center>
	<th width=15><center>Rombel Kelas XII BHS</th></center>  -->
	</tr>";
	

	$L=1;
	foreach ( $fivesdrafts as $alumni_polkam ) 
	{
		echo "<tr class='hentry alternate'><td align=center>".$L++ . " </td>
		<td align=center>" .$alumni_polkam->foto .  " </td>
		<td align=center>" ."<a href=\"admin.php?page=".$_REQUEST['page']."&crud=guru&nim=".$alumni_polkam->nim."\">". $alumni_polkam->nim. "</a><br/>" .  " </td>
		<td align=center>" .$alumni_polkam->nama .  " </td>
		<td align=center>" .$alumni_polkam->tempat_lahir .  " </td>
		<td align=center>" .$alumni_polkam->tanggal_lahir.  " </td>
		<td align=center>" .$alumni_polkam->alamat.  " </td>
		<td align=center>" .$alumni_polkam->no_hp.  " </td>
		<td align=center>" .$alumni_polkam->email.  " </td>
		<td align=center>" .$alumni_polkam->blog.  " </td>
		<td align=center>" .$alumni_polkam->program_studi.  " </td>
		<td align=center>" .$alumni_polkam->angkatan.  " </td>
		<!-- <td align=center>" .$alumni_polkam->fax.  " </td>
		<td align=center>" .$alumni_polkam->email ."</td>
		<td align=center>" .$alumni_polkam->website.  " </td>
		<td align=center>" .$alumni_polkam->kelas_x ."</td>
		<td align=center>" .$alumni_polkam->kelas_xi ."</td>
		<td align=center>" .$alumni_polkam->kelas_xii ."</td>
		<td align=center>" .$alumni_polkam->rombel_x ."</td>
		<td align=center>" .$alumni_polkam->rombel_xiipa ."</td>
		<td align=center>" .$alumni_polkam->rombel_xiips ."</td>
		<td align=center>" .$alumni_polkam->rombel_xibhs ."</td>
		<td align=center>" .$alumni_polkam->rombel_xiiipa ."</td>
		<td align=center>" .$alumni_polkam->rombel_xiiips ."</td>
		<td align=center>" .$alumni_polkam->rombel_xiibhs ."</td> -->
		</tr>";
			
	}
	echo "</table>";
	?>
	<h3><a href="admin.php?page=<?=$_REQUEST['page']?>&crud=panel">Kembali</a></h3>
	<?
}

function update_data_sekolah(){
	$nama_sekolah = $_POST['nama_sekolah'];
	?>
	<form id="form1" name="form1" method="post" action="">
		<table class="form-table" >
		<tr>
		  <th><label for="nama_sekolah">Masukkan Nama Sekolah yang akan di UPDATE !</label></th>
		  <td>
			<input type="text" id="nama_sekolah" name="nama_sekolah" value="<?php echo $nama_sekolah;?>" class="regular-text">
			<br />
		  </td>
		</tr>		
		</table>
		<b><h3><input type="Submit" value="Cari!" /></h3></b>
	</form>
	<?
	echo ("<br>");
	global $wpdb;
	$hasilcari = Array();
	$hasilcari = $wpdb->get_results("SELECT * FROM sekolah WHERE nama_sekolah LIKE '%$nama_sekolah%'");
	foreach($hasilcari as $sekolah){
		echo "<a href=\"admin.php?page=".$_REQUEST['page']."&crud=form&nss=".$sekolah->nss."\">". $sekolah->nama_sekolah. "</a><br/>";
	}
	echo ("<br>");
	echo ("<br>");
	?>
	<h3><a href="admin.php?page=<?=$_REQUEST['page']?>&crud=panel">Kembali</a></h3>
	<?
}
	
function telah_update_data_sekolah(){	
	//echo "Update data sekolah";
	if($_POST['submit']=="Update"){
		echo "Anda telah <b>BERHASIL</b> update data sekolah";
		echo ("<br>");
		echo ("<br>");
		global $wpdb;
		$nama_sekolah =  $_POST['nama_sekolah'] ;
		$alamat =  $_POST['alamat'] ;
		$status =  $_POST['status'] ;
		$desa =  $_POST['desa'] ;
		$kecamatan =  $_POST['kecamatan'] ;
		$kode_pos =  $_POST['kode_pos'] ;
		$kota =  $_POST['kota'] ;
		$provinsi =  $_POST['provinsi'] ;
		$telp =  $_POST['telp'] ;
		$fax =  $_POST['fax'] ;
		$email =  $_POST['email'] ;
		$website =  $_POST['website'] ;
		$kelas_x =  $_POST['kelas_x'] ;
		$kelas_xi =  $_POST['kelas_xi'] ;
		$kelas_xii =  $_POST['kelas_xii'] ;
		$rombel_x =  $_POST['rombel_x'] ;
		$rombel_xiipa =  $_POST['rombel_xiipa'] ;
		$rombel_xiips =  $_POST['rombel_xiips'] ;
		$rombel_xibhs =  $_POST['rombel_xibhs'] ;
		$rombel_xiiipa =  $_POST['rombel_xiiipa'] ;
		$rombel_xiiips =  $_POST['rombel_xiiips'] ;
		$rombel_xiibhs =  $_POST['rombel_xiibhs'] ;
		$nss = $_POST['nss'];
		$SQL = "UPDATE `sekolah` set
		`nss` ='$nss',
		`nama_sekolah` = '$nama_sekolah' ,
		`alamat` = '$alamat',
		`status` = '$status',
		`desa` = '$desa',
		`kecamatan` = '$kecamatan',
		`kode_pos` = '$kode_pos',
		`kota` = '$kota',
		`provinsi` = '$provinsi',
		`telp` = '$telp',
		`fax` = '$fax',
		`email` = '$email',
		`website` = '$website',
		`kelas_x` ='$kelas_x',
		`kelas_xi` = '$kelas_xi',
		`kelas_xii` = '$kelas_xii',
		`rombel_x` = '$rombel_x',
		`rombel_xiipa` = '$rombel_xiipa',
		`rombel_xiips` = '$rombel_xiips',
		`rombel_xibhs` = '$rombel_xibhs',
		`rombel_xiiipa` = '$rombel_xiiipa',
		`rombel_xiiips` = '$rombel_xiiips',
		`rombel_xiibhs` = '$rombel_xiibhs'
		WHERE 
		`nss` = '$nss' ;";
		$wpdb->query($SQL);
		echo $SQL;
		?>
		<h3><a href="admin.php?page=<?=$_REQUEST['page']?>&crud=panel">Kembali</a></h3>
		<?
		
	}
	
	echo "<!--pre>";
	print_r($_GET);
	print_r($_POST);
	print_r($_REQUEST);
	echo "</pre-->";
}
	
function form_update_data_sekolah(){
	if(isset($_GET['nss']) || isset($_POST['nss'])){
		//echo "ID sekolahnya adalah: " .$_GET['nss'];
		$nss = $_GET['nss'];
		global $wpdb;
		$hasilcari = $wpdb->get_results("SELECT * FROM sekolah WHERE nss = '$nss'");
		foreach($hasilcari as $sekolah){
			?>
			<form id="form1" name="form1" method="post" action="admin.php?page=<?=$_REQUEST['page']?>&crud=telah&nss="<? echo $sekolah->nss; ?>">
				<table class="form-table" >
				<input type=hidden name=nss value="<?=$sekolah->nss?>" />
                		
			<tr>
			  <th><label for="nss">Nomor Statistik Sekolah</label></th>
			  <td>
				<input type="text" id="nss" name="nss" value="<?php echo $sekolah->nss;?>" class="regular-text">
				<br />
			  </td>
			</tr>

			<tr>
			  <th><label for="nama_sekolah">Nama Sekolah</label></th>
			  <td>
				<input type="text" id="nama_sekolah" name="nama_sekolah" value="<?php echo $sekolah->nama_sekolah;?>" class="regular-text">
				<br />
			  </td>
			</tr>
			
			<tr>
			  <th><label for="alamat">Alamat</label></th>
			  <td>
				<textarea name="alamat" id="alamat" rows="5" cols="30"><?php echo $sekolah->alamat;?></textarea>
				<br />
			  </td>
			</tr>
			
			<tr>
			  <th><label for="status">Status</label></th>
			  <td>
				<!-- <input type="text" id="status" name="staStatustus" value="<?php echo $sekolah->status;?>" class="regular-text"> -->
				<SELECT NAME="status" ID="status">
				  <OPTION VALUE=""></OPTION>
				  <OPTION VALUE="NEGERI" <?php selected( $sekolah->status, 'NEGERI' ); ?>>NEGERI</OPTION>
				  <OPTION VALUE="SWASTA" <?php selected( $sekolah->status, 'SWASTA' ); ?>>SWASTA</OPTION>
				  <OPTION VALUE="Lainnya" <?php selected( $sekolah->status, 'Lainnya' ); ?>>Lainnya</OPTION>
				</SELECT>
				<br />
				<span class="description">Pilih status sekolah !. </span>
			  </td>
			</tr>
			
		<tr>
		  <th><label for="desa">Desa</label></th>
		  <td>
			<input type="text" id="desa" name="desa" value="<?php echo $sekolah->desa;?>" class="regular-text">
			<br />
		  </td>
		</tr>
			<tr>
		  <th><label for="kecamatan">Kecamatan</label></th>
		  <td>
			<!-- <input type="text" id="kecamatan" name="kecamatan" value="<?php echo $sekolah->kecamatan;?>" class="regular-text"> -->
			<SELECT NAME="kecamatan" ID="kecamatan">
			  <OPTION VALUE=""></OPTION>
			  <OPTION VALUE="BANGKINANG" <?php selected( $sekolah->kecamatan, 'BANGKINANG' ); ?>>BANGKINANG</OPTION>
			  <OPTION VALUE="BANGKINANG BARAT" <?php selected( $sekolah->kecamatan, 'BANGKINANG BARAT' ); ?>>BANGKINANG BARAT</OPTION>
			  <OPTION VALUE="BANGKINANG SEBERANG" <?php selected( $sekolah->kecamatan, 'BANGKINANG SEBERANG' ); ?>>BANGKINANG SEBERANG</OPTION>
			  <OPTION VALUE="KAMPAR" <?php selected( $sekolah->kecamatan, 'KAMPAR' ); ?>>KAMPAR</OPTION>
			  <OPTION VALUE="KAMPAR TIMUR" <?php selected( $sekolah->kecamatan, 'KAMPAR TIMUR' ); ?>>KAMPAR TIMUR</OPTION>
			  <OPTION VALUE="KAMPAR UTARA" <?php selected( $sekolah->kecamatan, 'KAMPAR UTARA' ); ?>>KAMPAR UTARA</OPTION>
			  <OPTION VALUE="RUMBIO JAYA" <?php selected( $sekolah->kecamatan, 'RUMBIO JAYA' ); ?>>RUMBIO JAYA</OPTION>
			  <OPTION VALUE="SALO" <?php selected( $sekolah->kecamatan, 'SALO' ); ?>>SALO</OPTION>
			  <OPTION VALUE="Lainnya" <?php selected( $sekolah->kecamatan, 'Lainnya' ); ?>>Lainnya</OPTION>
			</SELECT>
			<br />
		  </td>
		</tr>
			
			<tr>
		  <th><label for="kode_pos">Kode Pos</label></th>
		  <td>
			<input type="text" id="kode_pos" name="kode_pos" value="<?php echo $sekolah->kode_pos;?>" class="regular-text">
			<br />
		  </td>
		</tr>
		
		<tr>
		  <th><label for="kota">Kab/Kota</label></th>
		  <td>
			<!-- <input type="text" id="kota" name="kota" value="<?php echo $sekolah->kota;?>" class="regular-text"> -->
			<SELECT NAME="kota" ID="kota">
			  <OPTION VALUE=""></OPTION>
			  <OPTION VALUE="KAMPAR" <?php selected( $sekolah->kota, 'KAMPAR' ); ?>>KAMPAR</OPTION>
			  <OPTION VALUE="Lainnya" <?php selected( $sekolah->kota, 'Lainnya' ); ?>>Lainnya</OPTION>
			</SELECT>
			<br />
		  </td>
		</tr>
		
		<tr>
		  <th><label for="provinsi">Provinsi</label></th>
		  <td>
			<!-- <input type="text" id="provinsi" name="provinsi" value="<?php echo $sekolah->provinsi;?>" class="regular-text"> -->
			<SELECT NAME="provinsi" ID="provinsi">
			  <OPTION VALUE=""></OPTION>
			  <OPTION VALUE="RIAU" <?php selected( $sekolah->provinsi, 'RIAU' ); ?>>RIAU</OPTION>
			  <OPTION VALUE="Lainnya" <?php selected( $sekolah->provinsi, 'Lainnya' ); ?>>Lainnya</OPTION>
			</SELECT>
			<br />
		  </td>
		</tr>
		<tr>
		  <th><label for="telp">Telepon</label></th>
		  <td>
			<input type="text" id="telp" name="telp" value="<?php echo $sekolah->telp;?>" class="regular-text">
			<br />
		  </td>
		</tr>
		<tr>
		  <th><label for="fax">No Fax</label></th>
		  <td>
			<input type="text" id="fax" name="fax" value="<?php echo $sekolah->fax;?>" class="regular-text">
			<br />
		  </td>
		</tr>
		<tr>
		  <th><label for="email">Email</label></th>
		  <td>
			<input type="text" id="email" name="email" value="<?php echo $sekolah->email;?>" class="regular-text">
			<br />
		  </td>
		</tr>
		<tr>
		  <th><label for="website">Website</label></th>
		  <td>
			<input type="text" id="website" name="website" value="<?php echo $sekolah->website;?>" class="regular-text">
			<br />
		  </td>
		</tr>
		<tr>
		  <th><label for="kelas_x">Siswa Kelas X</label></th>
		  <td>
			<input type="text" id="kelas_x" name="kelas_x" value="<?php echo $sekolah->kelas_x;?>" class="regular-text">
			<br />
		  </td>
		  </tr>
		  <tr>
		  <th><label for="kelas_xi">Siswa Kelas XI</label></th>
		  <td>
			<input type="text" id="kelas_xi" name="kelas_xi" value="<?php echo $sekolah->kelas_xi;?>" class="regular-text">
			<br />
		  </td>
		  </tr>
		  <tr>
		  <th><label for="kelas_xii">Siswa Kelas XII</label></th>
		  <td>
			<input type="text" id="kelas_xii" name="kelas_xii" value="<?php echo $sekolah->kelas_xii;?>" class="regular-text">
			<br />
		  </td>
		  </tr>
		  <tr>
		  <th><label for="rombel_x">Rombel Kelas X</label></th>
		  <td>
			<input type="text" id="rombel_x" name="rombel_x" value="<?php echo $sekolah->rombel_x;?>" class="regular-text">
			<br />
		  </td>
		  </tr>
		  <tr>
		  <th><label for="rombel_xiipa">Rombel Kelas XI IPA</label></th>
		  <td>
			<input type="text" id="rombel_xiipa" name="rombel_xiipa" value="<?php echo $sekolah->rombel_xiipa;?>" class="regular-text">
			<br />
		  </td>
		  </tr>
		  <tr>
		  <th><label for="rombel_xiips">Rombel Kelas XI IPS</label></th>
		  <td>
			<input type="text" id="rombel_xiips" name="rombel_xiips" value="<?php echo $sekolah->rombel_xiips;?>" class="regular-text">
			<br />
		  </td>
		  </tr>
		  <tr>
		  <th><label for="rombel_xibhs">Rombel Kelas XI BHS</label></th>
		  <td>
			<input type="text" id="rombel_xibhs" name="rombel_xibhs" value="<?php echo $sekolah->rombel_xibhs;?>" class="regular-text">
			<br />
		  </td>
		  </tr>
		  <tr>
		  <th><label for="rombel_xiiipa">Rombel Kelas XII IPA</label></th>
		  <td>
			<input type="text" id="rombel_xiiipa" name="rombel_xiiipa" value="<?php echo $sekolah->rombel_xiiipa;?>" class="regular-text">
			<br />
		  </td>
		  </tr>
		  <tr>
		  <th><label for="rombel_xiiips">Rombel Kelas XII IPS</label></th>
		  <td>
			<input type="text" id="rombel_xiiips" name="rombel_xiiips" value="<?php echo $sekolah->rombel_xiiips;?>" class="regular-text">
			<br />
		  </td>
		  </tr><tr>
		  <th><label for="rombel_xiibhs">Rombel Kelas XII BHS</label></th>
		  <td>
			<input type="text" id="rombel_xiibhs" name="rombel_xiibhs" value="<?php echo $sekolah->rombel_xiibhs;?>" class="regular-text">
			<br />
		  </td>
		  </tr>
		  </table><br>
				<b><h3><input type=submit name=submit value="Update">&nbsp;&nbsp;&nbsp;</b></h3>
				<b><h3><input type=reset name=reset value="Reset"></b></h3>
				<h3><a href="admin.php?page=<?=$_REQUEST['page']?>&crud=update">Kembali</a></h3>
			</form>
			
			<?php
		}

	}
} 
?>